package samples.chapter05;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Chapter05BookJpaService {

    @Autowired
    Chapter05BookJpaDao bookJpaDao;

    public void addBook(Chapter05Book book) {
        bookJpaDao.save(book);
    }

    public Page<Chapter05Book> getBookByPage(Pageable pageable) {
        return bookJpaDao.findAll(pageable);
    }

    public List<Chapter05Book> getBooksByAuthorStartingWith(String author) {
        return bookJpaDao.getBooksByAuthorStartingWith(author);
    }

    public List<Chapter05Book> getBooksByPriceGreaterThan(Float price) {
        return bookJpaDao.getBooksByPriceGreaterThan(price);
    }

    public Chapter05Book getMaxIdBook() {
        return bookJpaDao.getMaxIdBook();
    }

    public List<Chapter05Book> getBookByIdAndAuthor(String author, Integer id) {
        return bookJpaDao.getBookByIdAndAuthor(author, id);
    }

    public List<Chapter05Book> getBooksByIdAndName(String name, Integer id) {
        return bookJpaDao.getBooksByIdAndName(name, id);
    }
}
